<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>test page</title>
</head>
<body>
receiver: <input type="text" id="receiver" value="10001"/>
message: <input type="text" id="message" value="hello"/>
<a id="sendbtn" href="#nogo">send</a>


<script type="text/javascript" src="http://imstatic.bang.360.cn/js/jquery_plugin/jquery.js"></script>
<script type="text/javascript" src="http://imstatic.bang.360.cn/local-storage.js"></script>

<script type="text/javascript">

(function(){
function Logger(t, l, h, w)
{
  this.cnt = 0;
  var n = $('<div/>');
  n.attr('class', 'debug');
  n.css('fontSize', '9pt');
  n.css('position', 'absolute');
  n.css('textAlign', 'left');
  n.css('top', t);
  n.css('left', l);
  n.css('width', w);
  n.css('height', h);
  n.css('border', '1px solid');
  n.css('color', '#333');
  n.css('backgroundColor', '#eee');
  n.css('verticalAlign', 'bottom');
  n.css('overflow', 'auto');
  this.el = n;
  $(document.body).append(this.el);
}

Logger.prototype.hide = function() {
  this.el.css('display','none');
  $(document).remove(this.el);
}

Logger.prototype.reset = function()
{
  this.cnt = 0;
  this.el.empty();
}

Logger.prototype.println = function(str, color)
{
  if(this.cnt ++ > 80)
  {
    this.cnt = 0;
    this.el.empty();    
  }
  var node = $('<span/>').text(str);
  if (color) {
    node.css('color', color);
  }
  this.el.append(node);
  this.el.append($('<br/>'));
  this.el.scrollTop(this.el.height());
}

Logger.prototype.dump = function(o) {
  for(var k in o) {
    this.println('obj[\'' + k + '\']=' + o[k]);
  }
}

Logger.prototype.assert = function(message, test) {
  this.println(message + (test ? ' PASSED' : ' FAILED'), test ? '#5a5' : '#a55');
}

window.Logger = Logger;

})();

var StringifyPaseTest = function() {
//var o = {x:"value"};
//var o2 = Parse(Stringify(o));
//logger.assert("stringify " + Stringify(o), o.x == o2.x);

//var o = {d:1,s:'v',f:7.5,o:{x:'value'}};
//var o2 = Parse(Stringify(o));
//logger.assert("stringify " + Stringify(o), o2.d == 1 && o2.s == 'v' && o2.o.x == 'value');

//var o = {"type":"ce_poll_suc","rsp":{sender:2000000002,timestamp:1368762995,message:"hello"}};
//var o2 = Parse(Stringify(o));
//logger.assert("stringify " + Stringify(o), o2.type == "ce_poll_suc" && o2.rsp.sender==2000000002 && o2.rsp.message == "hello");

  // var o = {"type":"ce_poll_ok","rsp":[{"type":4,"subtype":0,"sender":288297970,"receiver":127646892,"timestamp":1369985112,"message":"asdfasdfasfsd"}]};
  var o = {"type":"ce_poll_ok","rsp":[{"type":4,"subtype":0,"sender":288297970,"receiver":127646892,"timestamp":1369985112,"message":"asdfasdfasfsd"}, {"type":4,"subtype":0,"sender":288297970,"receiver":127646892,"timestamp":1369985112,"message":"asdfasdfasfsd"}]};
  logger.println(Stringify(o));
};

var LocalStoreTest = function() {
  var o = {d:1,s:'v',f:7.5,o:{x:'value'}};
  LocalStore.Write('key', o);
  var o2 = LocalStore.Read('key');
  logger.assert(Stringify(o) + " local store", Stringify(o) == Stringify(o2));

  var o = {"type":"ce_poll_suc","rsp":{sender:2000000002,timestamp:1368762995,message:"hello"}};
  LocalStore.Write('key', o);
  var o2 = LocalStore.Read('key');
  logger.assert(Stringify(o) + " local store", Stringify(o) == Stringify(o2));

};

var ClearLocalStore = function() {
  for(var i = 0; i < 100; ++i) {
    LocalStore.Remove('qim' + i);
    logger.println("remove qim" + i); 
  }
};

function ArraySliceTest() {
  var CHANNEL_LIST = [0, 1, 2, 3, 4];
  var active_idx = 2;
  logger.println(CHANNEL_LIST.slice(0, active_idx).join());
  logger.println(CHANNEL_LIST.slice(active_idx + 1).join());
  logger.println(CHANNEL_LIST.slice(0, active_idx).concat(CHANNEL_LIST.slice(active_idx + 1)).join());
}

$(document).ready(function() {
  window.logger = new Logger('50px', '10px', '80%', '50%');
  // StringifyPaseTest(); 
  // LocalStoreTest();
  // ClearLocalStore(); 
  ArraySliceTest();
});

</script>
</body>
</html>
